package com.liruo.learn.spring.mvc.enumconverter;

import com.liruo.learn.spring.mvc.model.enumeration.GenderEnum;
import org.springframework.core.convert.converter.Converter;

public  class IntToGenderEnumConverter implements Converter<Integer, GenderEnum> {
    @Override
    public GenderEnum convert(Integer source) {
        for (GenderEnum genderEnum : GenderEnum.values()) {
            if(genderEnum.getSource().equals(source)){
                return genderEnum;
            }
        }
        throw new IllegalArgumentException(GenderEnum.class.getName() + " has not the source=" + source);
    }
}